<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%String basePath = request.getContextPath(); %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>聚餐活动发布</title>
<link rel="stylesheet" href="<%=basePath%>/resource/iKindEditor/editor/plugins/code/prettify.css" />
<link rel="stylesheet" href="<%=basePath%>/resource/iKindEditor/editor/themes/default/default.css" />
<link rel="stylesheet" href="<%=basePath%>/resource/css/common.css" />
<link rel="stylesheet" href="<%=basePath%>/resource/css/jquery-ui.css" />
<link rel="stylesheet" href="<%=basePath%>/resource/css/jquery.Jcrop.css" />

<script charset="utf-8" src="<%=basePath%>/resource/iKindEditor/editor/kindeditor.js"></script>
<script charset="utf-8" src="<%=basePath%>/resource/iKindEditor/editor/lang/zh_CN.js"></script>
<script charset="utf-8" src="<%=basePath%>/resource/iKindEditor/editor/plugins/code/prettify.js"></script>
<script charset="utf-8" type="text/javascript" src="<%=basePath%>/resource/js/articleEditor.js"></script>
<script charset="utf-8" type="text/javascript" src="<%=basePath%>/resource/js/jquery/jquery-1.8.2.js"></script>  
<script charset="utf-8" type="text/javascript" src="<%=basePath%>/resource/js/jquery/jquery-ui.js"></script>     
<script charset="utf-8" type="text/javascript" src="<%=basePath%>/resource/js/mydatepicker.js"></script>    
<script charset="utf-8" type="text/javascript" src="<%=basePath%>/resource/js/jquery/jquery.ui.datepicker-zh-CN.js"></script>
<script charset="utf-8" type="text/javascript" src="<%=basePath%>/resource/js/jquery/jquery.form.js"></script> 
<script charset="utf-8" type="text/javascript" src="<%=basePath%>/resource/js/jquery/jquery.Jcrop.js"></script>
<script charset="utf-8" type="text/javascript" src="<%=basePath%>/resource/js/ajax_constants.js"></script>
<script charset="utf-8" type="text/javascript" src="<%=basePath%>/resource/js/honeycombtool.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	loadPosition();
	var dateInput = $('#beginTime');
	loadDatepicker(dateInput);
	dateInput = $('#endTime');
	loadDatepicker(dateInput);
	$("#submitButton").click(checkAndSubmit);
});
function loadPosition(){
	$.ajax({
			url: '<%=basePath%>/position/getPositions',
			type: 'post',
			async: true,
			dataType: 'json',
			success: function(res) {	
				if(res.result == AjaxMsgConstants.SUCCESS){
						var listLength = res.positions.length;
						for(var i = 0 ;i < listLength;i++){
							createOptions(res.positions[i]);
							}
					}
			}
		});
};
function createOptions(optionsData){
	$("#createOptions").append("<option value="+optionsData.positionId+">"+optionsData.positionName+"</option>");
}
function filesubmit() {
    $('#myform').ajaxSubmit({
        dataType:  'json',
        url : '<%=getServletContext().getInitParameter("uploaderURL")%>',
        type: 'POST',
        success:function(res){
			if(res.error == 0) {
				$("#actionPicUrl").val(res.url);
				$("#imgPath").html("<img width='100px;' height='100px;' src="+res.url+">"+"</img>");
				
			}
			else {
				alert("系统保存文件错误！错误信息：" + res.message);
			}
        }
    });

}
function checkAndSubmit() {
	articleEditor_inputEditor.sync(); // 将编辑框中的内容同步到textarea编辑框中来
	var imgUrl = $("#actionPicUrl").val();
	var title = $("#actionTitle").val();
	var useMoney = $("#useMoney").val();
	var peopleNum = $("#peopleNum").val();
	var content = articleEditor_inputEditor.text().replace(new RegExp("<\\s*img\\s+([^>]*)>", 'g'), "").replace(new RegExp("<\\s*embed\\s+([^>]*)>", 'g'), "");
	var positionOption = $("#createOptions").val();
	if (CHECK.isEmpty(imgUrl) || CHECK.isEmpty(changeScript(title)) 
			|| !CHECK.isNumber(useMoney) || !CHECK.isNumber(peopleNum)
			|| CHECK.isEmpty(content) || CHECK.isEmpty(positionOption)) {
		alert("请完善数据");
	} else {
		$("#actionForm").submit();
	}
}
</script>
</head>
<body>       
<%@ include file="top.jsp" %>
<div style="width: 1000px;height: 800px;margin: 0 auto;margin-top: 130px;border: 1px solid #C3E99E;">
<div style="margin: 0 auto;width: 1000px;height: 46px;line-height: 45px;text-align: left;font-size:18px;background:white;">
		<div style="margin-top:2px;width: 900px;height: 42px;border-bottom:1px solid #8CC700;margin-left: 50px;">	
		
		<b>&nbsp;&nbsp;活动发布  </b>
	
		</div>
		
		</div>
		
		<form action="<%=getServletContext().getInitParameter("uploaderURL")%>" method="post" id="myform" name="myform" enctype="multipart/form-data" target="douplaod">
			
			<div style="width: 100%;height: 45px;line-height: 45px;text-align: left;margin-left:80px;">
				<div style="float: left;width: 350px;height: 100%;">
					活动图片：<input type="file" name="file" id="filess" onchange="filesubmit()">
				</div>
				<div id="checkNoticeTitle" style="float: left;width: 240px;height: 100%;font-size: 13px;">
				</div>
				<div style="clear:both"></div>
		</div>
		</form>
		<iframe name="douplaod" style="display:none;">
			
		</iframe>
		<div style="width: 100%;height: 100px;line-height: 45px;text-align: left;margin-left:80px;">
				<div id="imgPath" style="float: left;width: 350px;height: 100%;margin-left: 65px;">
					<img  style="max-width:100px ;max-height:100px" src="<%=request.getContextPath() %>/resource/images/pages/logo.png" >
				</div>
				<div style="clear:both"></div>
		</div>
		<form id="actionForm" action="<%=basePath%>/play/dine/admin/addActionApply" method="post">
		<div style="width: 100%;height: 45px;line-height: 45px;text-align: left;margin-left:80px;margin-top: 10px;">
					<div style="float: left;width: 290px;height: 100%;">
						活动小区：<select name="positionId" id="createOptions">
						
								</select>
					</div>
					<div id="checkActionTitle" style="float: left;width: 240px;height: 100%;font-size: 13px;">
					</div>
					<div style="clear:both"></div>
			</div>
			<div style="width: 100%;height: 45px;line-height: 45px;text-align: left;margin-left:80px;margin-top: 10px;">
					<div style="float: left;width: 290px;height: 100%;">
						活动主题：<input id="actionTitle" maxlength="30" name="actionTitle"  type="text" style="height:25px;width:200px;" value="最多30字符">
					</div>
					<div id="checkActionTitle" style="float: left;width: 240px;height: 100%;font-size: 13px;">
					</div>
					<div style="clear:both"></div>
			</div>
			<div style="width: 100%;height: 45px;line-height: 45px;text-align: left;margin-left:80px;">
					<div style="float: left;width: 290px;height: 100%;">
						个人花费：<input id="useMoney" maxlength="30" name="useMoney"  type="text" style="height:25px;width:200px;" >
					</div>
					<div id="checkUseMoney" style="float: left;width: 240px;height: 100%;font-size: 13px;">
					</div>
					<div style="clear:both"></div>
			</div>
			<div style="width: 100%;height: 45px;line-height: 45px;text-align: left;margin-left:80px;">
					<div style="float: left;width: 290px;height: 100%;">
						活动人数：<input id="peopleNum" maxlength="30" name="peopleNum"  type="text" style="height:25px;width:200px;" >
					</div>
					<div id="checkPeopleNum" style="float: left;width: 240px;height: 100%;font-size: 13px;">
					</div>
					<div style="clear:both"></div>
			</div>
			<div style="width: 100%;height: 45px;line-height: 45px;text-align: left;margin-left:80px;">
					<div style="float: left;width: 290px;height: 100%;">
						活动时间：<input id="beginTime" maxlength="30" name="beginTime" readonly="readonly"  type="text" style="height:25px;width:95px;" >-<input id="endTime" maxlength="30" readonly="readonly" name="endTime"  type="text" style="height:25px;width:95px;" >
								
					</div>
					<div id="checkActionTime" style="float: left;width: 240px;height: 100%;font-size: 13px;">
					</div>
					<div style="clear:both"></div>
			</div>
			<input name="actionPicUrl" id="actionPicUrl" type="hidden" value="<%=request.getContextPath() %>/resource/images/pages/logo.png">
			<div style="width: 100%;height: 45px;line-height: 45px;text-align: left;margin-left:80px;">
				<div style="float: left;width: 100%;height: 100%;">
					<div style="float: left;">活动描述：</div>
					<div style="float: left;"><textarea id="inputTextArea" name="content" style="display: bolck;width:600px; height:200px;"></textarea></div>
					<div style="float: left;">&nbsp;&nbsp;</div>
				</div>
				<div id="checkNoticeContext" style="float: left;width: 240px;height: 100%;font-size: 13px;">
				</div>
				<div style="clear:both"></div>
			</div>
			<div style="margin-top: 200px;margin-left: 140px;">
			<input type="button" id="submitButton" class="button_style" value="立即提交">
		</div>
		</form>
</div>
<%@ include file="foot.jsp" %>
</body>
</html>